package user;

import javax.servlet.http.HttpSession;
import javax.servlet.http.HttpServletRequest;

import model.UserInfo;

import com.jfinal.aop.Interceptor;
import com.jfinal.core.ActionInvocation;

public class UserInterceptor implements Interceptor {

	@Override
	public void intercept(ActionInvocation user) {
		String name=user.getController().getPara("user");
		String pass=user.getController().getPara("pass");
		UserInfo userinfo=UserInfo.dao.findFirst("select * from userinfo where name=? and password=?"
				, name,pass);
		if(userinfo!=null){
			user.getController().setSessionAttr("name",name);
			user.getController().setSessionAttr("pass", pass);
			user.getController().getSession().setMaxInactiveInterval(20*60);
			user.invoke();
		}
		else{
			user.getController().setAttr("msg", "登录失败～");
			user.getController().render("/userman/logint.html");
		}
	}

}
